<?php
// @formatter:off
/**
 * @file WCCronTool.php
 * @author Alejandro Dario Simi
 * @date $Date: 2013-08-20 00:23:06 +0000 (Tue, 20 Aug 2013) $
 *
 * $Id: WCCronTool.php 102 2013-08-20 00:23:06Z daemonraco@gmail.com $
 * $URL: http://wcomix.googlecode.com/svn/tags/wcomix-1.0.0.1/includes/WCCronTool.php $
 */
// @formatter:on

/**
 * @abstract
 * @class WCCronTool This class represents in a generic way the specification of a
 * cron operation and it's used by WCCron. Every cron operation must be an
 * inheritance of this class.
 */
class WCCronTool {
	/**
	 * @var boolean This flag indicates the list of options and their
	 * configuration are already loaded.
	 */
	protected $_optionsLoaded = false;
	/**
	 * @var WCConnection Database pointer shortcut.
	 */
	protected $_db;
	/**
	 * @var string Database tables' prefix shortcut.
	 */
	protected $_dbprefix;
	/**
	 * Class constructor.
	 */
	public function __construct() {
		//
		// Loading global pointers.
		global $wcDatabaseAccess;
		//
		// Loading shortcuts.
		// @{
		$this->_db = WCConnection::Instance();
		$this->_dbprefix = $wcDatabaseAccess["prefix"];
		// @}
		//
		// Loading options list.
		$this->loadOptions();
	}
	//
	// Public methods.
	/**
	 * This method is called by 'WCCron' when a tool must perform its tasks.
	 *
	 * @param string $spacer This s a prefix to add on each prompted line.
	 */
	public function run($spacer = "") {
		//
		// This method must be implemented by a sub-class, otherwise it
		// aborts.
		die(__CLASS__."::".__FUNCTION__."() Subclass Resposabillity\n");
	}
	/**
	 * This method is called by 'WCCron' to check a specific tool's automatic
	 * options.
	 *
	 * @param string[] $options List of options to be checked.
	 */
	public function checkParams($options = null) {
		//
		// Loading global pointers.
		global $wcOptions;
		//
		// Checking options.
		$wcOptions->check($options);
	}
	/**
	 * This method is called by 'WCCron' when a tool must prompt its help
	 * text.
	 *
	 * @param string $spacer This s a prefix to add on each prompted line.
	 */
	public function showHelp($spacer = "") {
		//
		// This method must be implemented by a sub-class, otherwise it
		// aborts.
		die(__CLASS__."::".__FUNCTION__."() Subclass Resposabillity\n");
	}
	//
	// Protected methods.
	/**
	 * This method is called by 'WCCron' when a tool must load and configure
	 * its options and parameters.
	 * It must also modify variable '$this->_optionsLoaded'.
	 */
	protected function loadOptions() {
		//
		// This method must be implemented by a sub-class, otherwise it
		// aborts.
		die(__CLASS__."::".__FUNCTION__."() Subclass Resposabillity\n");
	}
}
?>